package com.example.lambda.Fork;

import org.junit.Test;

import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.stream.LongStream;

public class TestJoin {


    @Test
    public void test(){
        ForkJoinPool pool = new ForkJoinPool();
        ForkJoinTask<Long> task = new ForkJoinCalculate(0,100000000L);
        long sum = pool.invoke(task);
        System.out.println(sum);
    }


    // java8 并行流

    @Test
    public void test2(){
        LongStream.rangeClosed(0,1000000000L).parallel()
                .reduce(0,Long::sum);
    }
}
